package com.douqu.game.core.config;

import com.douqu.game.core.config.common.CommonData;
import com.douqu.game.core.entity.GameObject;
import com.douqu.game.core.factory.ConstantFactory;
import com.douqu.game.core.factory.DataFactory;
import com.douqu.game.core.factory.LoadFactory;
import com.douqu.game.core.util.LoadUtils;
import com.douqu.game.core.util.LogUtils;

/**
 * @author wangzhenfei
 *         2017-11-28 16:03
 *         军团连锁配置
 */
public class MasterTrainConfig extends GameObject {
    /**选中权重**/
    public int weight;
    /**普通改变的值**/
    public CommonData[] normalChange;
    public int totalNormalChangeWeight;
    /**高级改变值**/
    public CommonData[] seniorChange;
    public int totalSeniorChangeWeight;
    /**等级上限**/
    public int[] maxLevel;


    @Override
    public boolean check()
    {
        if(DataFactory.getInstance(LoadFactory.isTestLoad()).getGameObject(DataFactory.ATTRIBUTE_KEY, id) == null){
            LogUtils.debug("主将培养属性找不到：" + id);
            return false;
        }
        return true;
    }


    @Override
    public boolean setVariable(String key, String value) {
        if("normalChange".equals(key))
        {
            normalChange = LoadUtils.loadCommonDataToArray(key, value);

            for(CommonData data : normalChange){
                totalNormalChangeWeight += data.value;
            }
            return true;
        }else  if("seniorChange".equals(key))
        {
            seniorChange = LoadUtils.loadCommonDataToArray(key, value);
            for(CommonData data : seniorChange){
                totalSeniorChangeWeight += data.value;
            }
            return true;
        }else  if("maxLevel".equals(key))
        {
            String[] temp = value.split(ConstantFactory.SEMICOLON);
            int size = temp.length;
            maxLevel = new int[size];
            for(int i = 0; i < size; i++){
                maxLevel[i] = Integer.valueOf(temp[i]);
            }
            return true;
        }
        else
            return super.setVariable(key, value);
    }


}
